package com.geetour.columbus.region.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.geetour.columbus.common.model.R.ProvincePage;
import com.geetour.columbus.common.service.IProvincePageService;
import com.geetour.columbus.common.utils.StringUtil;

@Controller
public class ProvincePageController {

    private IProvincePageService provincePageServiceImpl;

    @Autowired
    public void setProvincePageServiceImpl(IProvincePageService provincePageServiceImpl) {
        this.provincePageServiceImpl = provincePageServiceImpl;
    }

    @RequestMapping("/region/provincePageQuery.jsp")
    public String query(ModelMap modelMap, ProvincePage province) {
        if (province != null) {
            List<ProvincePage> provincePageList =  provincePageServiceImpl.findProvincePages(province);
            modelMap.put("provincePageList", provincePageList);
        }
        return "/region/provincePageList.html";
    }
    
    @RequestMapping("/region/provincePageAdd.jsp")
    public String addBatch(ModelMap modelMap, String provinces) {
        if (provinces != null) {
            List<String> list = StringUtil.lineInput(provinces);
            int result = provincePageServiceImpl.insertProvincePageNames(list);
            modelMap.put("result", result);
        }
        return "/region/provincePageAdd.html";
    }

    @RequestMapping("/region/provincePageEdit.jsp")
    public String edit(ModelMap modelMap, ProvincePage province) {
        int result = provincePageServiceImpl.updateProvincePage(province);
        modelMap.put("result", result);
        return "/region/provincePage.html";
    }

    @RequestMapping("/region/provincePageItem.jsp")
    public String item(ModelMap modelMap, Long id) {
        ProvincePage item = provincePageServiceImpl.findProvincePageById(id);
        modelMap.put("provincePage", item);
        return "/region/provincePage.html";
    }

    @RequestMapping("/region/provinceList.jsp")
    public String list(ModelMap modelMap, ProvincePage province) {
        List<ProvincePage> list = provincePageServiceImpl.findProvincePages(province);
        modelMap.put("provincePageList", list);
        return "/region/provincePageList.html";
    }
    
    @RequestMapping("/region/provincePageDelete.jsp")
    public String delete(ModelMap modelMap, ProvincePage province) {
        provincePageServiceImpl.deleteProvincePageById(province.getId());
        province.setId(null);
        return this.query(modelMap, province);
    }

}
